/**
 * 智能填写
 * @author Moxun<mxnstrive@gmail.com>
 * @copyright © 2024 http://jinpin.love/
 */
 import SalaryInfo from '@/constants/salaryinfo.js'
 import JobFiller from './JobFiller'
  
 /**
  * 填写
  * @param {*} target 
  * @param {string} data 输入内容
  * @param {*} keyword 关键字列表
  */
 function fill(target, data, keyword) {
     var _this = target
     var aicalc = keyword.find(m => m.propType == 'aicalc');
     if (aicalc) {
       var ary = [];
       aicalc.keys.forEach(k => {
         k.keywords.forEach(w => {
           var ary1 = w.keyword.split('-');
           if (ary1.length >= 4)
             ary.push({ keyName: ary1[0], id: parseInt(ary1[1]), min: parseInt(ary1[2]), max: parseInt(ary1[3]) });
         });
       })
       SalaryInfo.calc_rules = ary;
     }
  
     function createContext(keyword) {
         return { target, content: data, keyword, propName: keyword.propName}
     }
  
     keyword.forEach(m => {
       JobFiller.fill(createContext(m))
  
       const val = _this[m.propName]
       if (!val || val.length > 0) {
           return
       }
     })
 }
  
  
 /**
  * 删除
  * @param {string} data 输入内容
  * @param {*} keyword 关键字列表
  */
 function del(data, keyword) {
   keyword.forEach(m => {
     if (m.isPrivate) {
       data = data.replaceAll(m.keyword, '');
     } else {
       let reg = null
       try {
         reg = new RegExp(m.keyword, 'g')
       } catch (err) {
         // console.error(err)
       }
       if (reg) {
         data = data.replaceAll(reg, '')
       }
     }
   })
   return data
 }
  
 export default {
   fill,
   del,
 }
 